# 你想将一个多层嵌套的序列展开成一个单层列表

from collections import Iterable

def flatten(items, ignore_types = (str, bytes)):
    for item in items:
        if isinstance(item, Iterable) and not isinstance(item, ignore_types):
            yield from flatten(item)
        else:
            yield item

items = [1, [2, [3, 4], 5], 6]
for i in flatten(items):
    print(i, end=' ')

print()

items = ['Dave', 'Paula', ['Thomas', 'Lewis']]
for i in flatten(items):
    print(i, end=' ')
print()
